package com.bins.code.generator.model;

import com.bins.code.generator.config.builder.ConfigBuilder;
import com.bins.code.generator.enums.TemplateEnum;
import com.bins.code.generator.function.ConverterFileName;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;

import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

@Slf4j
@Getter
@Setter
@NoArgsConstructor
public class ValidGroupsModel extends BaseModel {

    public ValidGroupsModel(ConfigBuilder configBuilder) {
        super(configBuilder);
    }

    /**
     * 文件模板
     */
    private TemplateEnum template = TemplateEnum.VALID_GROUPS;

    private String className;

    /**
     * 包导入信息
     */
    private Set<String> importPackages = new TreeSet<>();

    /**
     * 转换输出文件名称
     */
    private ConverterFileName converterFileName = (entityName -> entityName);

    public Set<String> getImportPackages() {
        return importPackages;
    }

    public void setImportPackages(Set<String> importPackages) {
        if (CollectionUtils.isEmpty(importPackages)) {
            importPackages = new HashSet<>();
        }
        if (this.isLombok()) {
            importPackages.add(Data.class.getCanonicalName());
        }
        if (this.isSerialVersionUID()) {
            importPackages.add(java.io.Serializable.class.getCanonicalName());
        }
        this.importPackages = importPackages;
    }
}
